package com.rd.student.jike.class2.xuezhixin.day0801;

import java.util.Arrays;
import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] arr = {1,3,5,7,9,11,13,15,17,0};
        for (int i = 0;i<arr.length;i++){
            System.out.print(arr[i] + "  ");
        }
        System.out.println("您要在谁的后面添加新元素：");
        int num = scanner.nextInt();
        int len = 0;   // 要复制的元素个数
        for (int i = 0;i<arr.length;i++){
            if (arr[i] == num){
                len = i+1;
            }
        }
        if (len == 0){
            System.out.println("您选择的数字该数组不存在");
        }

        int[] arr1 = new int[arr.length];
        System.arraycopy(arr,0,arr1,0,len);
        System.out.println("您要添加的新元素是：");
        int num1 = scanner.nextInt();
        arr1[len] = num1;
        System.arraycopy(arr,len,arr1,len+1,arr.length - len-1);

        for (int i = 0;i<arr1.length;i++){
            System.out.print(arr1[i] + "  ");
        }
    }
}
